package top.ckxgzxa.newscms.validation;

import top.ckxgzxa.newscms.validation.annotation.PasswordMatch;
import top.ckxgzxa.newscms.entity.dto.UserDto;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 赵希奥
 * @date 2022/5/25 12:17
 * @gitHub https://github.com/CKXGZXA
 * @gitee https://gitee.com/ckxgzxa
 * @description:
 */
public class PasswordMatchValidator implements ConstraintValidator<PasswordMatch, UserDto> {

    @Override
    public void initialize(PasswordMatch constraintAnnotation) {
        ConstraintValidator.super.initialize(constraintAnnotation);
    }

    @Override
    public boolean isValid(UserDto userDto, ConstraintValidatorContext constraintValidatorContext) {
        return userDto.getPassword().equals(userDto.getMatchPassword());
    }
}
